<?php

	class Utils {
	
		function __construct(){
			$this->load->library('Physician');
			$this->load->library('Visit');
			
		}
		
		/**
		 * Accepts as a param a database result array from the physician table,
		 * constructs a physician object out of it
		 * @param Array $result
		 * @returns physician object
		 */
		public static function createPhysicianObject($result){
			$physician = new Physician();
			
			$physician->setId($result['id']);
			$physician->setFirstName($result['firstName']);
			$physician->setLastName($result['lastName']);
			$physician->setEmail($result['email']);
			$physician->setGender($result['gender']);
			$physician->setBirthDate($result['birthDate']);
			$physician->setTitle($result['title']);
			$physician->setPassword($result['password']);
			$physician->setNote($result['note']);
			$physician->setEmployed($result['employed']);
			$physician->setCreated($result['created']);
			$physician->setBirthPlaceCity($result['birthPlaceCity']);
			$physician->setBirthPlaceCountry($result['birthPlaceCountry']);
			$physician->setPhoneNumber($result['phoneNumber']);
			$physician->setAddress($result['address']);
			$physician->setStatus($result['status']);
			$physician->setUpdated($result['updated']);
			
			return $physician;
		}
		
		public static function createVisitObject($result){
			$visit = new Visit();
			
			$visit->setId($result['id']);
			$visit->setAccepted($result['accepted']);
			$visit->setPhysicianId($result['physicianId']);
			$visit->setPatientId($result['patientId']);
			$visit->setNote($result['note']);
			$visit->setDischarged($result['discharged']);
			$visit->setLengthOfStay($result['lengthOfStay']);
			$visit->setCaseDescription($result['caseDescription']);
			
			return $visit;
		}
		
		public static function calculateLengthOfStay(DateTime $accepted, DateTime $discharged){
			//TODO test
			return $accepted->diff($discharged)->days;
			
		}
		
	}


?>